/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package databaseHandling;

import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.sql.SQLException;
import model.Bruger;
import model.Rabat;

/**
 *
 * @author Jeppe
 */
public abstract class BrugerHandler {


    public static Bruger getBruger(String brugerNavn) throws RemoteException, SQLException {
        Bruger bruger = null;
        ResultSet rs = DatabaseHandler.getInstance().select("CALL hentBruger ('" + brugerNavn + "')");
        if (rs.next()) {
            bruger = new Bruger(rs.getInt("id"), rs.getString("brugerNavn"), rs.getString("password"));
        }
        return bruger;
    }
    
    public static Rabat getRabatTilknyttetBrugerOgVareGruppe(int brugerid, int vareGruppeid)throws RemoteException, SQLException{
        Rabat rabat = null;
        ResultSet rs = DatabaseHandler.getInstance().select("CALL HentRabat(" + brugerid + ", " + vareGruppeid + ")");
        if(rs.next()){
            rabat = new Rabat(rs.getInt("id"), rs.getInt("rabatSats"));
        }
        return rabat;
    }
}
